<div class="row">
    <div class="button-container mb10">
	<?php 
        echo Yii::app()->user->checkAccess('position|add')?CHtml::link('添加推荐位','javascript:void(0);',array('class'=>'button editShow' ,'url'=>$this->createUrl('position/add' ))):'';
    ?>
    </div>
    <table class="table table-bordered table-hover definewidth">
    	<thead>
    		<tr>
    			<th style="width: 80px;"><?php echo $this->_attributeLabels['sort'] ?></th>
                <th style="width: 80px;"><?php echo $this->_attributeLabels['posid'] ?></th>
    			<th><?php echo $this->_attributeLabels['position_name'] ?></th>
                <th><?php echo $this->_attributeLabels['cate_id'] ?></th>
                <th><?php echo $this->_attributeLabels['model_id'] ?></th>
                <th><?php echo $this->_attributeLabels['disable'] ?></th>
    			<th style="width:150px;">管理操作</th>
    		</tr>
    	</thead>
        <tbody>
        <?php if( !empty($list) ){foreach( $list as $aVal ){ ?>
            <tr>
                <td><input type="text" value="<?php echo $aVal['sort']; ?>" class="width20 ajaxOperateSort" url="<?php echo $this->createUrl('position/ajaxSort' ,array('posid'=>$aVal['posid'])) ?>" /></td>
                <td><?php echo $aVal['posid'] ?></td>
                <td><?php echo $aVal['position_name'] ?></td>
                <td><?php echo $aVal['cate_id'] ? $aVal['cate_id'] : '全部'; ?></td>
                <td><?php echo $aVal['model_id'] ? $aVal['model_id'] : '全部' ?></td>
                <td>
                <?php
                    $sTextRed = $aVal['disable']==1 ? '' : 'red';
                    echo Yii::app()->user->checkAccess('position|ajaxDiable') ? 
                         CHtml::link($aVal['disable']==1 ? '禁用' : '启用' ,'javascript:void(0)' ,array('url'=>$this->createUrl('position/ajaxDisable' ,array('posid'=>$aVal['posid'])) ,'class'=>"ajaxOperateReplace $sTextRed")) : '';
                ?>
                </td>
                <td>
                <?php
                    echo CHtml::link('编辑' ,'javascript:void(0);',array('class'=>'editShow' ,'url'=>$this->createUrl('position/edit' ,array('posid'=>$aVal['posid'])))) ."\n";
                    echo CHtml::link('删除','javascript:void(0);',array('url'=>$this->createUrl('position/delete' ,array('posid'=>$aVal['posid'])) ,'class'=>'delete'));
                ?>
                </td>
            </tr>
        <?php }} ?>               
        </tbody>
</table>
<!-- 分页page start -->
<div class="table-bottom-operate">
    <div class="inline pull-left table-operate">
    </div>
    <div class="inline pull-right page">
        <?php //$this->widget('LinkPager',array('pages' => $pages)); ?>
    </div>
	
</div>
<!-- 分页page end -->
</div>
<script type="text/javascript">
function add(url){
        var Overlay = BUI.Overlay,
        Form = BUI.Form;
        var form,
        dialog = new Overlay.Dialog({
            title:'添加模型',
            width:600,
            height:500,
            loader : {
              url : url,
              autoLoad : false, //不自动加载
              lazyLoad : false,
              callback : function(){
                var node = dialog.get('el').find('form');//查找内部的表单元素
                form = new Form.HForm({
                  srcNode : node,
                  autoRender : true
                });
              }
            },
            mask:false,
            success : function(){
              //可以直接action 提交
              form && form.submit(); //也可以form.ajaxSubmit(params);
            }
          });
      //dialog.show();
      form && form.destroy(); //移除掉之前的表单
        dialog.show();
        var params = {a : count}; //加载表单的参数
        dialog.get('loader').load(params);
}
      var count = 0;
      $('.editShow').on('click',function () {
    
        var url = $(this).attr('url');
        add(url);
      });
  </script>
